<%-- 
    Document   : UserPage
    Created on : 23.04.2011, 22:24:55
    Author     : ain
--%>

<%@page import="unc.pds.model.DiaryRemote"%>
<%@page import="unc.pds.model.UserRemote"%>
<%@page import="unc.pds.data.Consts"%>
<%@page import="unc.pds.util.ArchImpl"%>
<%@page import="unc.pds.util.Arch"%>
<%@page import="unc.pds.service.*"%>
<%@page import="javax.naming.InitialContext"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Diaries</title>
    </head>
    <body>
        <%
                ServiceBeanRemote sbr = (ServiceBeanRemote)session.getAttribute("service");
                UserRemote user = sbr.getUser();
                DiaryRemote[] diarys = user.getDiares();
                for (int i=0;i<diarys.length;i++){
                    out.println(
                            "<a href=DiaryPage.jsp?id="+diarys[i].getKey()+">"+diarys[i].getCaption()+"</a><br>"
                            );
                }
        %>
        <form action="DiariesPage.jsp">
            <input type="text" name="post" value="post">
            <input type="text" name="caption" value="caption">
            <input type="text" name="user" value="ain">
            <input type="submit" name="newpost" value="newpost">
        </form>
        <%
            if(request.getParameter("newpost")!=null){
                Arch doc = new ArchImpl("root",null);
                doc.addChild(new ArchImpl(Consts.CONT__DIARY_POST,request.getParameter("post")));
                doc.addChild(new ArchImpl(Consts.ATTR__DIARY_CAPTION,request.getParameter("caption")));
                user.addDiary(doc);
                response.sendRedirect("DiariesPage.jsp?id="+user.getKey());
            }
        %>
    </body>
</html>
